#!/bin/bash
#
# 26/02/2008 - Ricardo Brito - ricardo@rbncurriculo.cjb.net
#
# Pode ser executado automaticamente fazendo 'crontab -e' e colocando (para rodar todos os dias as 3.30 da manha):
# SHELL=/bin/bash
# # Backup Data.fs do Zope
# 30 3 * * * /path/do/backupZeo.sh
#
# Ou
# Inserindo a seguinte linha no /etc/crontab
# 30 3 * * * root /path/do/backupZeo.sh

export PYTHONPATH=/opt/Plone-2.5.5/Python-2.4.4/lib/python2.4

PYTHON=/opt/Plone-2.5.5/Python-2.4.4/bin/python
ZOPEUTIL=/opt/Plone-2.5.5/bin
BCK_DIR=/var/backups/Plone-2.5.5
ZEO_DIR=/opt/Plone-2.5.5/zeocluster/server
ZEO_PORT=8100
ADM_USER=plone
echo ":: Relatorio de backup do Zeo  ::" >> $BCK_DIR/message.txt


date >> $BCK_DIR/message.txt

find $BCK_DIR -type f -name "*.fs" -ctime +2 -exec rm -fv {} \; >> $BCK_DIR/message.txt
find $ZEO_DIR -name "*.fs" -exec cp -fv {} $BCK_DIR \; >> $BCK_DIR/message.txt

#echo "Fazendo o pack do ZEO ..." >> $BCK_DIR/message.txt
#$PYTHON $ZOPEUTIL/zeopack.py -p $ZEO_PORT -d 7 2> tempfile
#cat tempfile >> $BCK_DIR/message.txt

#echo "Fazendo backup incremental do Data.fs ..." >> $BCK_DIR/message.txt
#$PYTHON $ZOPEUTIL/repozo.py -B -v -r $BCK_DIR -f $ZEO_DIR/var/Data.fs 2> tempfile

#cat tempfile >> $BCK_DIR/message.txt

# Copia em outro servidor
#echo "Copiando o backup no servidor (grande 10.1.2.150)..." >> $BCK_DIR/message.txt
#scp -rv $BCK_DIR/*.fs iaco@10.1.2.150:backup/ 2> tempfile
#scp -rv $BCK_DIR/*.dat iaco@10.1.2.150:backup/ 2> tempfile
#cat tempfile >> $BCK_DIR/message.txt

date >> $BCK_DIR/message.txt

cat $BCK_DIR/message.txt | mailx -s 'Cron Job: backup zope' $ADM_USER

rm $BCK_DIR/message.txt tempfile
